package org.apache.lucene.analysis.compound.morphology;

import org.apache.lucene.analysis.util.CharArraySet;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class poorvaroopa implements sandhi  {
	public boolean isInDict(CharArraySet dict, String word) {
		char [] warr = word.toCharArray();
		return dict.contains(warr, 0, word.length());
	}
	
	public String splitDevanagari(String word, CharArraySet dict){
		String a = null;
		for(int i = 0; i < word.length(); i++){
			if(word.substring(i, i+1).equals("ऽ")){
				String w1 = word.substring(0, i);
				String w2 = "अ" + word.substring(i+1);
				if(isInDict(dict,w1) && isInDict(dict,w2)){
					a = w1 + " " + w2;
					return a;
				}//end if
			}//end if
		}//end for
		return null;
	}//end method
	
	public String split(char[] wordArr, int len, CharArraySet dict){
		String word="";
		for (int i = 0; i < len; i++)
			word += wordArr[i];
		word = word.toLowerCase();
		String wd = splitDevanagari(word, dict);
		if (wd != null)
			return wd;
		for(int i = 0; i < word.length(); i++){
			if(word.substring(i, i+1).equals("e")){
				String w1 = word.substring(0, i) + "e";
				String w2 = "a" + word.substring(i+1);
				if(isInDict(dict, w1) && isInDict(dict, w2)){
					String a = w1 + " " + w2;
					return a;
				}//end if
			}//end if
			if(word.substring(i, i+1).equals("o")){
				String w1 = word.substring(0, i) + "o";
				String w2 = "a" + word.substring(i+1);
				if(isInDict(dict, w1) && isInDict(dict, w2)){
					String a = w1 + " " + w2;
					return a;
				}//end if
			}//end if
		}//end for
		 //return "Word doesn't contain this sandhi.";
		return null;
	}//end method
}//end class
